package com.abe.bathsystem.widget.dialog;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.EditText;

import com.abe.bathsystem.widget.OnOperateListener;
import com.abe.libcore.utils.normal.ToastUtils;

import net.yet.campusdev.R;

public class SerialSetPosAddDialog extends BaseDialog {
    private DialogContract.OnSerialPortSetAddressListener listener;

    public SerialSetPosAddDialog(@NonNull Context context, OnOperateListener operateListener) {
        super(context, operateListener);
    }

    public SerialSetPosAddDialog(@NonNull Context context) {
        super(context);
    }

    public void setListener(DialogContract.OnSerialPortSetAddressListener listener) {
        this.listener = listener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.item_view_v3_serial_set_address);
        final EditText item_set_serial_pos_sddress = findViewById(R.id.item_set_serial_pos_sddress);
        findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        findViewById(R.id.btn_set_serial_pos_address).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String x = item_set_serial_pos_sddress.getText().toString().trim();
                if (TextUtils.isEmpty(x)) {
                    ToastUtils.show(R.string.set_serial_pos_address);
                    return;
                }
                try {
                    int y = Integer.parseInt(x);
                    if (listener != null) {
                        listener.onSendCommand(y);
                    } else {
                        ToastUtils.show("请绑定回调监听");
                    }
                } catch (Exception e
                        ) {
                    e.printStackTrace();
                }
                dismiss();
            }
        });
    }
}
